#pragma once

#include "common.h"
#include "LfsrRegister.h"
#include <string>

template<int regSize = 2, int factorsSize=2>
class LfsrConfiguration
{
public:
	typedef LfsrRegister<regSize> Register;
	typedef LfsrRegister<factorsSize> Factorset;
	LfsrConfiguration(BYTE x, BYTE y = x)
	{ 
		for(int i = 0; i < regSize; i++)
		{
			reg.at(i) = x;
		}
		for(int i = 0; i < factorsSize; i++)
		{
			factors.at(i) = y;
		}
	}
	LfsrConfiguration(Register r, Factorset f)
		: reg(r), factors(f)
	{ }

	Register reg;
	Factorset factors;

	std::string toString() const
	{
		return "{ factors: " + factors.toStringAsRow() + ", register: " + reg.toStringAsRow() + " }";
	}
};

template <int regSize = 2, int factorsSize = 2>
class LfsrConfigurationComparer
{
private:
	LfsrRegisterComparer<regSize> _regcmp;
	LfsrRegisterComparer<factorsSize> _fcmp;

public:
	bool operator () (
		const LfsrConfiguration<regSize, factorsSize> &a, 
		const LfsrConfiguration<regSize, factorsSize> &b) const
	{
		bool f = _fcmp(a.factors, b.factors);
		if(!f)
		{
			if(!_fcmp(b.factors, a.factors))
			{
				return  _regcmp(a.reg, b.reg);
			}
		}
		return f;
	}
};